package com.ruoyi.common.core.redis;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.CommonUtil;

public class RedisInfo {
    public String keyPrefix;
    private String name;
    private Integer second = 0;
    private Integer minute = 0;
    private Integer hour = 0;
    private Integer day = 0;

    public RedisInfo() {
    }

    public String getName() {
        return this.name;
    }

    public RedisInfo setName(String name) {
        this.name = name;
        return this;
    }

    public int getExpire() {
        return this.day * 24 * 2600 + this.hour * 3600 + this.minute * 60 + this.second;
    }

    public String getKeyPrefix() {
        return this.keyPrefix;
    }

    public RedisInfo setKeyPrefix(String keyPrefix) {
        this.keyPrefix = keyPrefix;
        return this;
    }

    public Integer getSecond() {
        return this.second;
    }

    public RedisInfo setSecond(Integer second) {
        this.second = second;
        return this;
    }

    public Integer getMinute() {
        return this.minute;
    }

    public RedisInfo setMinute(Integer minute) {
        this.minute = minute;
        return this;
    }

    public Integer getHour() {
        return this.hour;
    }

    public RedisInfo setHour(Integer hour) {
        this.hour = hour;
        return this;
    }

    public Integer getDay() {
        return this.day;
    }

    public RedisInfo setDay(Integer day) {
        this.day = day;
        return this;
    }

    public String getKey(Object... values) {
        if (CommonUtil.isEmpty(values)) {
            return this.keyPrefix;
        } else {
            StringBuilder key = new StringBuilder();
            key.append(this.keyPrefix);
            Object[] var3 = values;
            int var4 = values.length;

            for(int var5 = 0; var5 < var4; ++var5) {
                Object obj = var3[var5];
                if (obj == null) {
                    key.append(CommonUtil.SPLIT_CODE + "null");
                } else {
                    key.append(CommonUtil.SPLIT_CODE + obj.toString());
                }
            }

            return key.toString();
        }
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
	public static List<RedisInfo> getList(Class clazz) {
        return (List) Arrays.stream(clazz.getFields()).map((f) -> {
            try {
                Object obj = f.get((Object)null);
                if (obj instanceof RedisInfo) {
                    return (RedisInfo)obj;
                }
            } catch (IllegalAccessException var2) {
                var2.printStackTrace();
            }

            return null;
        }).filter((a) -> {
            return a != null;
        }).collect(Collectors.toList());
    }

    public static void main(String[] args) {
        RedisInfo redisInfo = (new RedisInfo()).setKeyPrefix("3333").setName("_test");
        System.out.println(redisInfo.getKey(10, 20, null));
    }

    public String toString() {
        return JSONObject.toJSONString(this);
    }
}
